package com.ourteam.workspace.api;

import com.ourteam.frame.web.AbstractTreeNodeBuilder;
import com.ourteam.workspace.dao.WorkspaceDAOQueryBean;
import com.ourteam.workspace.service.IWorkspaceService;
import com.ourteam.workspace.service.WorkspaceServiceFactory;

public class WorkspaceRootNodeBuilder extends AbstractTreeNodeBuilder<Object, WorkspaceRootNodeBean> {

	private static final IWorkspaceService workspaceService = WorkspaceServiceFactory.getWorkspaceService();

	@Override
	public WorkspaceRootNodeBean[] getTreeNodeObjects(Object parentObject) throws Exception {
		return new WorkspaceRootNodeBean[] { new WorkspaceRootNodeBean() };
	}

	@Override
	public Object getNodeId(WorkspaceRootNodeBean childObject) throws Exception {
		return System.currentTimeMillis();
	}

	@Override
	public boolean isLeaf(WorkspaceRootNodeBean childObject) throws Exception {
		return false;
	}

	@Override
	public int getChildCount(WorkspaceRootNodeBean childObject) throws Exception {
		WorkspaceDAOQueryBean queryBean = new WorkspaceDAOQueryBean();

		return workspaceService.queryWorkspaceCount(queryBean);
	}

	@Override
	public String getNodeDefineId(WorkspaceRootNodeBean childObject) throws Exception {
		return "workspaceRoot";
	}

	@Override
	public Object converToParentObject(Object parent) throws Exception {
		return new WorkspaceRootNodeBean();
	}

}
